<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta charset="UTF-8">
    <title>登录</title>
</head>
<body>
<table>
    <tr>
        <td>手机号：</td>
        <td><input type="text" id="phone"/></td>
    </tr>
    <tr>
        <td>验证码：</td>
        <td><input type="text" id="code"/><input type="button" value="发送验证码" onclick="sendmsg(this);"></td>
    </tr>
    <tr>
        <td><input type="button" value="登录" onclick="login(this);"></td>
    </tr>
</table>
<script src="/web/public/js/jquery-2.2.4.min.js?v=201703311607" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    function sendmsg(obj) {
        var phone = $('#phone').val();
        $.ajax({
            type: "post",
            url: '/zzcx/user/login/send-msg',
            async: true,
            data: {phone: phone},
            dataType: "json",
            success: function (res_data) {
                if (false == res_data['flag']) {
                    alert(res_data['msg']);
                } else {
                    $(obj).val('发送成功');
                }
            },
            error: function () {
                alert('异常');
            }
        });
    }

    function login(obj) {
        var data = {
            phone: $('#phone').val(),
            code: $('#code').val(),
        };
        $.ajax({
            type: "post",
            url: '/zzcx/user/login/do-login',
            async: true,
            data: data,
            dataType: "json",
            success: function (res_data) {
                if (false == res_data['flag']) {
                    alert(res_data['msg']);
                } else {
                    alert('登录成功！')
                    document.cookie = 'access_token=' + res_data['data']['access_token'] + ';path=/;';
                }
            },
            error: function () {
                alert('异常');
            }
        });
    }

</script>
</body>
</html>